<template>
    <div class="add">
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
            <el-form-item label="评级">
                <el-rate v-model="form.rate"></el-rate>
            </el-form-item>
            <el-form-item label="内容" prop="content">
                <el-input v-model="form.content"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('form')">保存</el-button>
                <el-button @click="resetForm('form')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: 'add',
        props:{
            formData:{
                type:Object,
                default:0
            }
        },
        data(){
            return{
                http:'https://xcx.yichedi.com',
                form:{
                    rate:0,
                    content:''
                },
                rules: {
                    content: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ]
                }
            }
        },
        mounted(){
        },
        methods:{
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.form.art_id = this.formData.art_id
                        this.form.user_id = this.formData.user_id
                        this.form.reply_id = sessionStorage.getItem('userId')
                        this.form.pid = this.formData.id
                        this.form.fid = this.formData.fid
                        this.$store.dispatch('factory/reply', this.form).then(() => {
                            this.$notify({
                                title: '评论成功',
                                type: 'success'
                            })
                            this.$emit('close',false)
                        }).catch(() => {
                            this.$emit('close',false)
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    }
</script>

<style scoped>
</style>